package com.deschen.security.core.validate.code.config;

import com.deschen.security.core.properties.SecurityProperties;
import com.deschen.security.core.validate.code.image.ImageValidateCodeGenerator;
import com.deschen.security.core.validate.code.generator.ValidateCodeGenerator;
import com.deschen.security.core.validate.code.sms.DefaultSmsCodeSender;
import com.deschen.security.core.validate.code.sms.SmsValidateCodeSender;
import com.deschen.security.core.validate.code.sms.SmsValidateCodeGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author deschen
 * @Create 2019/8/18
 * @Description 验证码配置类
 * @Since 1.0.0
 */
@Configuration
public class ValidateCodeBeanConfig {

    @Autowired
    private SecurityProperties securityProperties;

    @Bean
    @ConditionalOnMissingBean(name = "imageValidateCodeGenerator")
    public ValidateCodeGenerator imageValidateCodeGenerator() {
        ImageValidateCodeGenerator imageValidateCodeGenerator = new ImageValidateCodeGenerator();
        imageValidateCodeGenerator.setSecurityProperties(securityProperties);
        return imageValidateCodeGenerator;
    }

    @Bean
    @ConditionalOnMissingBean(name = "smsValidateCodeGenerator")
    public ValidateCodeGenerator smsValidateCodeGenerator() {
        SmsValidateCodeGenerator smsValidateCodeGenerator = new SmsValidateCodeGenerator();
        smsValidateCodeGenerator.setSecurityProperties(securityProperties);
        return smsValidateCodeGenerator;
    }


    @Bean
    @ConditionalOnMissingBean(SmsValidateCodeSender.class)
    public SmsValidateCodeSender smsValidateCodeSender() {
        return new DefaultSmsCodeSender();
    }

}
